package com.ztao.redis;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Set;

@RestController
@RequestMapping("/redis")
public class RedisTest {
    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @RequestMapping("/listpush")
    public String testListPush(){
        redisTemplate.opsForList().leftPushAll("testListKey","k1", "k2", "k3");
        return "设置值";
    }

    @RequestMapping("/listpop")
    public String testListpop(){
        Object testListKey = redisTemplate.opsForList().rightPop("testListKey");
        System.out.println(testListKey);
        return "弹出值";
    }

    @RequestMapping("/zsetAdd")
    public String zsetAdd(){
        redisTemplate.opsForZSet().add("zsetKey", "a", 20);
        redisTemplate.opsForZSet().add("zsetKey", "b", 22);
        redisTemplate.opsForZSet().add("zsetKey", "c", 21);
        redisTemplate.opsForZSet().add("zsetKey", "d", 23);
        return "zset添加";
    }

    @RequestMapping("/zsetRange")
    public String zsetRange(){
        Set<Object> zsetKey = redisTemplate.opsForZSet().rangeByScore("zsetKey", 0, 30);
        System.out.println(zsetKey);
        return "zset获取值";
    }
}


